package com.zlq.cn.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.entity.Earthquake;
import com.zlq.cn.entity.EarthquakeArticle;
import com.zlq.cn.service.un.EarthquakeArticleService;
import com.zlq.cn.service.un.EarthquakeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Slf4j
@Api(tags = "公共-地震数据")
@RestController
@AllArgsConstructor
@Validated
@RequestMapping("/api/common/earthquake")
public class EarthquakeApiController extends BaseController {

    @Resource
    private EarthquakeService earthquakeService;

    @Resource
    private EarthquakeArticleService earthquakeArticleService;

    @SneakyThrows
    @ApiOperation(value = "地震列表", notes = "有分页")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "timeType", value = "按时间，1：最近24小时，2：最近48小时，3：最近7天，4：最近30天", paramType = "query", required = true),
            @ApiImplicitParam(name = "m", value = "按震级;小数", paramType = "query"),
            @ApiImplicitParam(name = "operator", value = "gt：大于，lt：小于", paramType = "query"),
    })
    @GetMapping("/list")
    public SignApiResult<Page<Earthquake>> list(Integer timeType, BigDecimal m, String operator) {
        return SignApiResult.resultSuccess(earthquakeService.list(super.getPage(), timeType, m, operator));
    }

    @ApiOperation(value = "地震文章列表", notes = "有分页")
    @GetMapping("/article/list")
    public SignApiResult<Page<EarthquakeArticle>> articleList() {
        return SignApiResult.resultSuccess(earthquakeArticleService.lambdaQuery()
                .eq(EarthquakeArticle::getEnable, 1)
                .page(super.getPage()));
    }
}
